﻿using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using AB.ServiceDirectory.Commons.DataFilters;

namespace AB.ServiceDirectory.Design.WebUserControls.Frame
{
    public partial class ServicePremiseFrame : UserControl
    {
        [Category("Manipulation")]
        public int ServiceId
        {
            get { return ViewState["ServiceId"] != null ? (int) ViewState["ServiceId"] : -1; }
            set { ViewState["ServiceId"] = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ServicePremiseFilter filter = ViewState["spFilter"] as ServicePremiseFilter ??
                                              new ServicePremiseFilter {ServiceId = ServiceId};
                ViewState["spFilter"] = filter;
            }
        }

        protected void ObjectDataSourceTeam_Selecting(object sender, ObjectDataSourceMethodEventArgs e)
        {
            var filter = ViewState["spFilter"] as ServicePremiseFilter;
            e.InputParameters["filter"] = filter;
        }

        protected void ButtonAssociatePremise_Click(object sender, EventArgs e)
        {
            AssociatePremiseFrame.ServiceId = ServiceId;
            AssociatePremiseFrame.Popup();
        }

        public void GridView_DataBind()
        {
            GridViewServicePremises.DataBind();
        }
    }
}